//抽象构件
abstract class Component {
    public abstract operate(): void
}

//具体构件
class ConcreateComponent extends Component {
    public operate(): void {
        console.log("do something");

    }
}

//装饰角色
abstract class Decorator extends Component {
    private component: Component;
    constructor(component: Component) {
        super()
        this.component = component
    }

    public operate(): void {
        this.component.operate()
    }
}

//具体装饰者
class ConcreateDecorateA extends Decorator {
    constructor(component: Component) {
        super(component)
    }
    //定义自己的修饰方法
    private methodA(): void {
        console.log("methodA 修饰");
    }
    //重写父类方法
    public operate(): void {
        this.methodA();
        super.operate()
    }
}

class ConcreateComponentB extends Decorator {
    constructor(component: Component) {
        super(component)
    }

    //定义自己的修饰方法
    private methodB(): void {
        console.log("methodB 修饰");
    }

    //重写父类方法
    public operate(): void {
        this.methodB()
        super.operate()
    }

}

const DecoratorTest = (): void => {
    //原有组件
    let component: Component = new ConcreateComponent()
    //第一次装饰
    component = new ConcreateDecorateA(component)
    //第二次装饰
    component = new ConcreateComponentB(component)
    //装饰后运行
    component.operate()
}

DecoratorTest()